package com.kucai.yifaqapp.ui.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.kucai.yifaqapp.R;

/**
 * 更换皮肤
 */
public class ChangeSkinActivity extends AppCompatActivity {
    private RelativeLayout left1;
    private RelativeLayout left2;
    private RelativeLayout left3;
    private ImageView img1;
    private ImageView img2;
    private ImageView img3;
    private LinearLayout skinbg;
    SharedPreferences sp;
    private RelativeLayout back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_skin);
        left1 = findViewById(R.id.left1);
        left2 = findViewById(R.id.left2);
        left3 = findViewById(R.id.left3);
        img1 = findViewById(R.id.img1);
        img2 = findViewById(R.id.img2);
        img3 = findViewById(R.id.img3);
        skinbg = findViewById(R.id.skinbg);
        back = findViewById(R.id.back);
        sp = this.getSharedPreferences("skinConfig", MODE_PRIVATE);
        int skintype = sp.getInt("skinId", 0);
        if (skintype == 17771) {
            skinbg.setBackgroundResource(R.mipmap.skin_bg1);
            img1.setVisibility(View.VISIBLE);
            img2.setVisibility(View.GONE);
            img3.setVisibility(View.GONE);
        } else if (skintype == 17772) {
            skinbg.setBackgroundResource(R.mipmap.skin_bg2);
            img1.setVisibility(View.GONE);
            img2.setVisibility(View.VISIBLE);
            img3.setVisibility(View.GONE);
        } else if (skintype == 17773) {
            skinbg.setBackgroundResource(R.mipmap.skin_bg3);
            img1.setVisibility(View.GONE);
            img2.setVisibility(View.GONE);
            img3.setVisibility(View.VISIBLE);
        }
        left1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                SpUtils.putInt(ChangeSkinActivity.this, "skinId", 17771);
                SharedPreferences.Editor editor = sp.edit();
                //写入数据
                editor.putInt("skinId", 17771);
                boolean b = editor.commit();
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                img1.setVisibility(View.VISIBLE);
                img2.setVisibility(View.GONE);
                img3.setVisibility(View.GONE);
            }
        });
        left2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sp.edit();
                //写入数据
                editor.putInt("skinId", 17772);
                boolean b = editor.commit();
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                img1.setVisibility(View.GONE);
                img2.setVisibility(View.VISIBLE);
                img3.setVisibility(View.GONE);
            }
        });
        left3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sp.edit();
                //写入数据
                editor.putInt("skinId", 17773);
                boolean b = editor.commit();
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                img1.setVisibility(View.GONE);
                img2.setVisibility(View.GONE);
                img3.setVisibility(View.VISIBLE);
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
